top-navigation<template>
	<view class="top-navigation" :style="{ height: navHeight + 'px', paddingTop: statusBarHeight + 'px', background: $props.bgcolor || '#fff'}">
		
			<!-- 左侧返回箭头 -->
			<view class="left-content" :style="{ width: `${menuButtonInfo.width}px`}">
				<slot name="lc">
					<view class="d-iocn">
						<up-icon name="arrow-left" size="24" @click="goBack"></up-icon>
					</view>
				</slot>
			</view>

			<!-- 中间标题 -->
			<view class="center-content">
				<text>{{$props.title}}</text>
			</view>

			<!-- 右侧胶囊占位 -->
			<view :style="{ width: `${menuButtonInfo.width}px`}"></view>
	</view>
</template>
<script setup>
import ENV_CONFIG from '@/env.js';
import { ref, onMounted } from 'vue';
import { setStorageSync, useRouter, getStorageSync } from '@/utils/utils';
import { onLoad, onHide, onShow } from '@dcloudio/uni-app';
// import uniIcons from '../../uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
const $props = defineProps(['title','bgcolor']);

// 获取系统信息
const systemInfo = uni.getSystemInfoSync();
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
// 状态栏高度
const statusBarHeight = ref(systemInfo.statusBarHeight);
// 导航栏总高度
const navHeight = ref(systemInfo.statusBarHeight + 44);
// 胶囊按钮高度
const menuButtonHeight = ref(menuButtonInfo.height);
// 胶囊按钮宽度
const menuButtonWidth = ref(menuButtonInfo.width);
// 胶囊按钮距顶部距离
const menuButtonTop = ref(menuButtonInfo.top);

let showBack = ref(false); //展示左边图标
let navBgColor = ref('#ADD8E6'); // 导航栏背景颜色
let Tab = ref('my');
// 提示登录
const tipLogin = () => {
	// sendMsg();
	uni.showModal({
		title: '登录提示',
		content: '您当前未登录，请先去登录',
		confirmColor: '#F45BFF',
		showCancel: true,
		confimrText: '登录',
		success: function (res) {
			if (res.confirm) {
				useRouter('/pages/login/login', null, 'navigateTo');
			}
		}
	});
};
// 返回上一页
const navBack = (router) => {
	if (router == 'home') {
		if (!getStorageSync('loginStatus')) {
			tipLogin();
			return;
		}
		setStorageSync('activeTab', true);
		useRouter('/pages/home/index', null, 'redirectTo');
	} else if (router == 'my') {
		setStorageSync('activeTab', false);
		useRouter('/pages/index/index', null, 'redirectTo');
	}
	// useRouter('/pages/login/login', null, 'navigateTo');
};

// 默认返回页面
function goBack(){
	uni.navigateBack()
}

onShow(() => {
	if (getStorageSync('activeTab')) {
		showBack.value = getStorageSync('activeTab');
	}
	console.log('这是icon', $props.showIcon);

	// showBack.value =

	// if (getStorageSync('activeTab') === 'home') {
	// 	Tab.value = getStorageSync('activeTab');
	// 	showBack.value = false;
	// }
	// if (getStorageSync('token')) {
	// 	// console.log('隐藏图标');
	// 	showBack.value = false;
	// }
});
</script>

<style lang="scss" scoped>
	.top-navigation{
		position: relative;
		display: flex;
		justify-content: space-between;
		width: 100%;
		padding: 0 6px;
		.left-content{
			overflow: hidden;
			height: 44px;
			.d-iocn {
				display: flex;
				align-items: center;
				position: relative;
				width: 100%;
				height: 100%;
			}
		}
		.center-content{
			overflow: hidden;
			height: 44px;
			line-height: 44px;
		}
		
	}
	
	
</style>
